var activityID = window.location.toString().split('/')[5];
var dt = $('.dataTablesAjax');
var ajax_datatable;
var TableDatatablesAjax = function () {
    var datatableAjax = function () {
        ajax_datatable = dt.DataTable({
            "processing": true,
            "serverSide": true,
            "searching": true,
            "searchDelay": 800,
            "search": {
                "regex": true
            },
            "ajax": {
                'url': '/admin/eticket/' + activityID + '/ticket/ajaxList?way='+getQueryString('way')+'&type='+getQueryString('type')
            },
            "pagingType": "full_numbers",
            "orderCellsTop": true,
            "dom": '<"html5buttons"B>lTfgitp',
            "buttons": [
                {extend: 'copy', title: 'permission'},
                {extend: 'csv', title: 'permission'},
                {extend: 'excel', title: 'permission'},
                {extend: 'pdf', title: 'permission'},
                {
                    extend: 'print',
                    customize: function (win) {
                        $(win.document.body).addClass('white-bg');
                        $(win.document.body).css('font-size', '10px');
                        $(win.document.body).find('table')
                            .addClass('compact')
                            .css('font-size', 'inherit');
                    }
                }
            ],
            "columns": [
                {
                    "data": "id",
                    "name": "id",
                    "orderable": true
                },
                {
                    "data": "way",
                    "name": "way",
                    "orderable": true
                },
                {
                    "data": "type",
                    "name": "type",
                    "orderable": true
                },
                {
                    "data": "number",
                    "name": "number",
                    "orderable": true
                },
                {
                    "data": "openid",
                    "name": "openid",
                    "orderable": true
                },
                {
                    "data": "status",
                    "name": "status",
                    "orderable": true
                },
                {
                    "data": "actionButton",
                    "name": "actionButton",
                    "type": "html",
                    "orderable": false
                }
            ],
            "drawCallback": function (settings) {
                ajax_datatable.$('.tooltips').tooltip({
                    placement: 'top',
                    html: true
                });
                var $statusLi = ajax_datatable.columns('.status').nodes().flatten().to$();
                $statusLi.each(function (i,item) {
                    if($(item).text()=='0'){
                        $(item).html('库中')
                    }else if($(item).text()=='1'){
                        $(item).html('<span style="color: greenyellow">被占</span>')
                    }else if($(item).text()=='2'){
                        $(item).html('<span style="color: steelblue">转出</span>')
                    }else if($(item).text()=='3'){
                        $(item).html('<span style="color: grey">销毁</span>')
                    }
                });
                var $wayTh = ajax_datatable.columns('.way').nodes().flatten().to$();
                $wayTh.each(function (i,item) {
                    if($(item).text()=='0'){
                        $(item).html('线上')
                    }else if($(item).text()=='1'){
                        $(item).html('线下')
                    }
                });
            },
            "language": {
                url: '/admin/i18n'
            }
        });
    };
    return {
        init: datatableAjax
    }
}();
$(function () {
    //修改面包屑标题
    var breadcrumbActive = $('.breadcrumb .active strong');
    var textTmp = breadcrumbActive.text();
    textTmp = getQueryString('type') + textTmp;
    getQueryString('way') == 0 ? textTmp = '线上' + textTmp : '';
    getQueryString('way') == 1 ? textTmp = '线下' + textTmp : '';
    breadcrumbActive.text(textTmp);


    TableDatatablesAjax.init();

});
